import 'package:flutter/material.dart';

class AlarmPage extends StatefulWidget {
  @override
  _AlarmPageState createState() => _AlarmPageState();
}

class _AlarmPageState extends State<AlarmPage> {
  String _selectedIssueType = "使用问题";
  final TextEditingController _feedbackController = TextEditingController();
  List<String> _uploadedImages = [];

  @override
  void dispose() {
    _feedbackController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("举报"),
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Text("请选择你想要举报的类型", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
                Text("*", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.red)),
              ],
            ),
            SizedBox(height: 8),
            Wrap(
              spacing: 8,
              runSpacing: 8,
              children: [
                _buildChip("违法违规"),
                _buildChip("色情低俗"),
                _buildChip("诈骗信息"),
                _buildChip("低差广告"),
                _buildChip("谩骂攻击"),
                _buildChip("危险行为"),
                _buildChip("不宜观看"),
                _buildChip("时政不实"),
                _buildChip("自残自杀"),
                _buildChip("其他"),
              ],
            ),
            SizedBox(height: 16),
            Row(
              children: [
                Text("举报描述", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
                Text("*", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.red)),
              ],
            ),
            SizedBox(height: 8),
            TextField(
              controller: _feedbackController,
              maxLines: 4,
              decoration: InputDecoration(
                border: OutlineInputBorder(),
                hintText: '请详细描述问题或者改进意见',
              ),
            ),
            Spacer(),
            Center(
              child: ElevatedButton(
                onPressed: () {
                    _showConfirmationDialog();
                },
                child: Text("提交"),
                style: ElevatedButton.styleFrom(
                  minimumSize: Size(double.infinity, 48), // 设置按钮宽度为屏幕宽度
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildChip(String label) {
    return SizedBox(
      width: (MediaQuery.of(context).size.width - 40) / 2 - 4, // 调整宽度
      child: FilterChip(
        label: Text(label, overflow: TextOverflow.ellipsis),
        selected: _selectedIssueType == label,
        onSelected: (bool selected) {
          setState(() {
            _selectedIssueType = label;
          });
        },
        backgroundColor: Colors.white, // 未选中时的背景颜色
        selectedColor: Colors.blue, // 选中时的背景颜色
      ),
    );
  }
   void _showConfirmationDialog() {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text("确认提交"),
          content: Text("确认提交吗？"),
          actions: [
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: Text("取消"),
            ),
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
                _showSuccessMessage();
              },
              child: Text("确定"),
            ),
          ],
        );
      },
    );
  }

  void _showSuccessMessage() {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text("提交成功"),
        duration: Duration(seconds: 2),
      ),
    );
  }
}
